updating the ratings

packages

library(tidyverse) # CRAN v1.3.0 
Registered S3 methods overwritten by 'dbplyr':
  method         from
  print.tbl_lazy     
  print.tbl_sql      
── Attaching packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
✓ ggplot2 3.3.1     ✓ purrr   0.3.4
✓ tibble  3.0.1     ✓ dplyr   1.0.0
✓ tidyr   1.1.0     ✓ stringr 1.4.0
✓ readr   1.3.1     ✓ forcats 0.5.0
── Conflicts ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
library(progress) # CRAN v1.2.2 
library(ggrepel)
library(lubridate)

Attaching package: ‘lubridate’

The following objects are masked from ‘package:base’:

    date, intersect, setdiff, union
library(conflicted) # CRAN v1.0.4
conflict_prefer("filter", "dplyr") 
[conflicted] Will prefer dplyr::filter over any other package
source("functions.R")
source("cleaning.R")
source("estimation.R")
source("graphs.R")
options(dplyr.summarise.inform = FALSE)

load up latest games and “pre” ratings

games <- read_rds("~/teaching/scoresway/rds/games.rds")
with_pre <- read_rds("wpre.rds")
with_pre

updated ratings

k <- 20
options(dplyr.summarise.inform = FALSE)
pb <- progress_bar$new(format = " progress [:bar] :percent eta: :eta", total = nrow(with_pre), width = 40)
with_pre %>% 
  mutate(rat=map2(this, pre, ~this_ratings(.x, .y, k, games))) %>% 
  mutate(post=map(rat, "r")) %>% 
  mutate(updates=map(rat, "d")) -> with_post

 progress [--------------]   3% eta:  7s
 progress [>-------------]   4% eta: 10s
 progress [>-------------]   6% eta: 10s
 progress [>-------------]   7% eta: 11s
 progress [>-------------]   8% eta: 12s
 progress [>-------------]  10% eta: 12s
 progress [=>------------]  11% eta: 12s
 progress [=>------------]  13% eta: 13s
 progress [=>------------]  14% eta: 13s
 progress [=>------------]  15% eta: 13s
 progress [=>------------]  17% eta: 14s
 progress [==>-----------]  18% eta: 14s
 progress [==>-----------]  20% eta: 13s
 progress [==>-----------]  21% eta: 13s
 progress [==>-----------]  23% eta: 13s
 progress [==>-----------]  24% eta: 14s
 progress [===>----------]  25% eta: 13s
 progress [===>----------]  27% eta: 13s
 progress [===>----------]  28% eta: 13s
 progress [===>----------]  30% eta: 13s
 progress [===>----------]  31% eta: 13s
 progress [====>---------]  32% eta: 13s
 progress [====>---------]  34% eta: 13s
 progress [====>---------]  35% eta: 12s
 progress [====>---------]  37% eta: 12s
 progress [====>---------]  38% eta: 12s
 progress [=====>--------]  39% eta: 12s
 progress [=====>--------]  41% eta: 11s
 progress [=====>--------]  42% eta: 11s
 progress [=====>--------]  44% eta: 11s
 progress [=====>--------]  45% eta: 11s
 progress [======>-------]  46% eta: 11s
 progress [======>-------]  48% eta: 10s
 progress [======>-------]  49% eta: 10s
 progress [======>-------]  51% eta: 10s
 progress [======>-------]  52% eta:  9s
 progress [======>-------]  54% eta:  9s
 progress [=======>------]  55% eta:  9s
 progress [=======>------]  56% eta:  8s
 progress [=======>------]  58% eta:  8s
 progress [=======>------]  59% eta:  8s
 progress [=======>------]  61% eta:  7s
 progress [========>-----]  62% eta:  7s
 progress [========>-----]  63% eta:  7s
 progress [========>-----]  65% eta:  7s
 progress [========>-----]  66% eta:  6s
 progress [========>-----]  68% eta:  6s
 progress [=========>----]  69% eta:  6s
 progress [=========>----]  70% eta:  6s
 progress [=========>----]  72% eta:  5s
 progress [=========>----]  73% eta:  5s
 progress [=========>----]  75% eta:  5s
 progress [==========>---]  76% eta:  4s
 progress [==========>---]  77% eta:  4s
 progress [==========>---]  79% eta:  4s
 progress [==========>---]  80% eta:  4s
 progress [==========>---]  82% eta:  3s
 progress [===========>--]  83% eta:  3s
 progress [===========>--]  85% eta:  3s
 progress [===========>--]  86% eta:  3s
 progress [===========>--]  87% eta:  2s
 progress [===========>--]  89% eta:  2s
 progress [============>-]  90% eta:  2s
 progress [============>-]  92% eta:  2s
 progress [============>-]  93% eta:  1s
 progress [============>-]  94% eta:  1s
 progress [============>-]  96% eta:  1s
 progress [=============>]  97% eta:  1s
 progress [=============>]  99% eta:  0s
 progress [==============] 100% eta:  0s
                                        
with_post

save

write_rds(with_post, "wpost.rds")

read

with_post <- read_rds("wpost.rds")

look at one

look at

see post values sorted in tabs

since_hrs <- 24
with_post %>% 
  mutate(latest=map_dbl(updates, ~max(.$time_stamp))) %>% 
  mutate(since=(now()-as_datetime(latest))/dhours(1)) %>% 
  filter(since<=since_hrs) -> wp2
wp2

see post values sorted in tabs

# read_csv("wanted.txt") %>% pull(want) -> wants
# wants
# with_post <- read_rds("wpost.rds")
# with_post %>% filter(league %in% wants) %>%  # edit/remove slice
wp2 %>% 
  arrange(desc(league)) %>% 
  select(post, updates, league) %>% 
  pwalk(~display(..1, ..2, ..3)) # first input to pwalk can be a df

plot

# time_graph("england 2", with_post)
map(wp2$league, ~time_graph(., with_post))
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
Joining, by = "team"
[[1]]

[[2]]

[[3]]

[[4]]

[[5]]

[[6]]

[[7]]

[[8]]

[[9]]

[[10]]

LS0tCnRpdGxlOiAidXBkYXRpbmciCm91dHB1dDogaHRtbF9ub3RlYm9vawotLS0KCiMgdXBkYXRpbmcgdGhlIHJhdGluZ3MKCiMjIHBhY2thZ2VzCgpgYGB7cn0KbGlicmFyeSh0aWR5dmVyc2UpICMgQ1JBTiB2MS4zLjAgCmxpYnJhcnkocHJvZ3Jlc3MpICMgQ1JBTiB2MS4yLjIgCmxpYnJhcnkoZ2dyZXBlbCkKbGlicmFyeShsdWJyaWRhdGUpCmxpYnJhcnkoY29uZmxpY3RlZCkgIyBDUkFOIHYxLjAuNApjb25mbGljdF9wcmVmZXIoImZpbHRlciIsICJk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